<template>
  <el-form :model="form" label-position="left">
    <el-row :gutter="10">
      <el-col :xs="24" :sm="24" :md="24" :lg="12" :xl="12">
        <el-form-item label="报表id">
          <el-input v-model="form.id" />
        </el-form-item>
      </el-col>
      <el-col :xs="24" :sm="24" :md="24" :lg="12" :xl="12">
        <el-form-item label="报表类型">
          <el-select v-model="form.configType" clearable placeholder="请选择：">
            <el-option
              v-for="item in configData.configTypeList"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item>
      </el-col>
      <el-col :xs="24" :sm="24" :md="24" :lg="12" :xl="12">
        <el-form-item label="名称">
          <el-input v-model="form.name" />
        </el-form-item>
      </el-col>
      <el-col :xs="24" :sm="24" :md="24" :lg="12" :xl="12">
        <el-form-item label="模块名称">
          <span >{{moduleName}}</span>
        </el-form-item>
      </el-col>
      <el-col :xs="24" :sm="24" :md="24" :lg="12" :xl="12">
        <el-form-item label="文件名">
          <el-input v-model="form.fileName" />
        </el-form-item>
      </el-col>
      <el-col :xs="24" :sm="24" :md="24" :lg="12" :xl="12">
        <el-form-item label="显示模式">
          <el-select
            v-model="form.importPattern"
            clearable
            placeholder="请选择："
          >
            <el-option
              v-for="item in configData.importPatternList"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item>
      </el-col>
      <el-col :span="24">
        <el-form-item label="备注">
          <el-input v-model="form.remark" type="textarea" />
        </el-form-item>
      </el-col>
    </el-row>
  </el-form>
  <div class="button-position">
    <el-button @click="updateVisible">取 消</el-button>
    <el-button type="primary" @click="add(formRef)">确 定</el-button>
  </div>
</template>
  <script setup>
import { ref, onMounted } from "vue";
import { ElNotification } from "element-plus";
import Api from "@/api/model/report";
const emit = defineEmits(["updatetable"]);
const form = ref({});
const configData = ref([]);
const moduleName = ref()
const props = defineProps({
  paramsData: {
    type: Object,
    defalut: {},
  },
});
onMounted(() => {
  getInit();
});
const getInit = async () => {
  let res = await Api.addBaseData.post(props.paramsData);
  console.log(res)
  if (res.code == "200") {
    form.value = res.data;
    configData.value = res.configData;
    moduleName.value = res.moduleName
  }
};
const updateVisible = () => {
  emit("updatetable");
};
const add = async (formRef) => {
  await formRef.validate((valid, fields) => {
    if (valid) {
      addData();
    }
  });
};

const addData = async () => {
  let params = {
    bean: form.value,
  };
  let res = await Api.saveBaseData.post(params);
  if (res.code == 200) {
    restAddFormData();
    ElNotification.success({
      title: "",
      message: "添加成功！",
      duration: 2000,
    });
    emit("updatetable", true);
  }
};
</script>